function doViewCard(id)
{
	ajax.send('?m=contacts&a=view&suppressHeaders=1&contact_id='+id, '',
		function (r) {
			var cd = Control('idContactDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doGetCard(id)
{
	go('?m=contacts&a=vcardexport&suppressHeaders=true&contact_id='+id);
}

function doEditCard(id, extra)
{
	ajax.send('?m=contacts&a=edit&suppressHeaders=1&contact_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idContactDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, doCloseContact).show();
			Calendar.setup(
				{
					inputField  : 'idBirthday',
					ifFormat    : '%Y-%m-%d',
					displayArea : 'idBirthdayD',
					daFormat    : SHDATEFORMAT,
					button      : 'idBirthdayB'
				}
			);

		}
	);
}

function doCloseContact()
{
	Control('idDeptSelector').destroy();
	Dialog('idContactDialog').hide();
}

function doSwitchTab(tab)
{
	if (tab.className == 'here') return;
	var c, i, r = tab.parentNode;
	for (i = 0; i < r.cells.length; i++) {
		if (r.cells[i].className == 'here') {
			c = r.cells[i];
			c.className = 'tab';
			break;
		}
	}
	tab.className = 'here';
	Control('id' + c.innerHTML).hide();
	Control('id' + tab.innerHTML).show();
}

function doChangeCompany()
{
	$('idDeptName').value = '';
	$('idDeptId').value = 0;
}

function doSelectDepartment(id)
{
	$('idDeptId').value = id;
	$('idDeptName').value = unescape($('idDept['+id+']').getAttribute('value'));
	Control('idDeptSelector').destroy();
}

function doShowDeptSelector()
{
	var c = $('idContactCompany');
	var id = c.options[c.selectedIndex].value;
	ajax.send('index.php?m=public&a=viewinfo&suppressHeaders=1&type=DepartmentList&id='+id, '',
		function(r) {
			var d = Control('idDeptSelector').create('div', 'topper', 'hidden');
			var error = r.indexOf('idDeptList') < 0;
			if (!error) {
				r = r.replace(/\n|\r/g,'');
				r = r.replace(/\<tr\>.*?\<\/tr\>/i,'');
				r = r.replace(/width="250px"/i, 'width="260px"');
				r = r.replace(/cellpadding="4"/i, 'cellpadding="0"');
			}
			d.innerHTML = r;
			Control(d).show();
			if (!error) initTree($('idDeptTree'));
			$('idContactDialog').onclick = function() {
				Control('idDeptSelector').destroy();
				this.onclick = undefined;
			}
			if (error) {
				Control(d).center();
			}
			else {
				var p = Control('idDeptName').position();
				Control(d).move(p.x + 3, p.y + 22);
			}
		}
	);
}
